<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <img id ="img" src="img/1.jpg"/>
    <br>
    <!-- <button id="up" onclick="up()">上一张</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button id="down" onclick="down()">下一张</button> -->
    <button id="up">上一张</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button id="down">下一张</button>
</body>
    <script>
        function up(){
            let img =document.getElementById("img");
            img.setAttribute("src","img/1.jpg");
        }

        function down(){
            let img =document.getElementById("img");
            img.setAttribute("src","img/2.jpg");
        }

        //第二种方法
        let upBtn = document.getElementById("up");
        upBtn.onclick = up;

        let downBtn = document.getElementById("down");
        downBtn.onclick = down;
        
    </script>
</html>